<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>let data = {
        name:'weiwei',
        age:22
    }
    
    const ojs =  new Observer(data)
    let vm  ={}
    vm = data = ojs
    
    function Observer(obj){
        const keys = Object.keys(obj)
    
        keys.forEach( item =>{
            Object.defineProperty(this,item,{
                get(){
                    return obj[item]
                },
                set(val){
                    obj[item] = val
                }
            })
            // console.log(this.name)
        })
    
    }
    </script>
</body>
</html>